package com.zw.april14thh.entity;

import org.springframework.stereotype.Component;

@Component
public class QueueNumber {
    private int aNumber;
    private int bNumber;
    private int cNumber;

    public QueueNumber() {
        this.aNumber = 0;
        this.bNumber = 0;
        this.cNumber = 0;
    }

    public synchronized void update(Integer type) { //使用 synchronized 对 update 方法进行同步处理
        if (type==1){
            this.aNumber++;
        }else if (type==2){
            this.bNumber++;
        }else if (type==4){
            this.cNumber++;
        }
    }

    public synchronized void resetting() { //使用 synchronized 对 update 方法进行同步处理
        this.aNumber = 0;
        this.bNumber = 0;
        this.cNumber = 0;
    }
    public synchronized void rollBack(Integer type) { //使用 synchronized 对 update 方法进行同步处理
        if (type==1){
            this.aNumber--;
        }else if (type==2){
            this.bNumber--;
        }else if (type==4){
            this.cNumber--;
        }
    }

    public synchronized String getQueueNumber(Integer type) { //使用 synchronized 对 getQueueNumber 方法进行同步处理
        String typeName ;
        int number;
        switch (type) {
            case 1:
                number = this.aNumber;
                typeName="A";
                break;
            case 2:
                number = this.bNumber;
                typeName="B";
                break;
            case 4:
                number = this.cNumber;
                typeName="C";
                break;
            default:
                throw new IllegalArgumentException("无效的队列类型!");
        }
        return typeName + String.format("%03d", number);
    }
}